
local md__jiebing = fk.CreateSkill {
    name = "md__jiebing",
  }
  
  Fk:loadTranslationTable{
    ["md__jiebing"] = "借兵",
    [":md__jiebing"] = "出牌阶段限一次，你可以获得一名有手牌的其他角色三张手牌，然后你受到1点伤害。若如此做，此阶段结束时，你交给其以此法获得的牌。",
  
    ["#md__jiebing"] = "借兵：获得一名角色三张手牌，受到1点伤害，本阶段结束时交给其以此法获得的牌",
    ["#md__jiebing-give"] = "借兵：你需交还 %dest %arg张牌",
    ["@@md__jiebing-inhand-round"] = "借兵",
    ["@md__jiebing-inhand-round"] = "借兵连续回合",
  
    ["$md__jiebing1"] = "将军~这些都赏给妾身好不好嘛~",
    ["$md__jiebing2"] = "这些人家不喜欢嘛~还给你吧~",
  }
  
  md__jiebing:addEffect("active", {
    mute = true,
    prompt = "#md__jiebing",
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
      return player:usedSkillTimes(md__jiebing.name, Player.HistoryPhase) == 0 -- (player:getMark("md__jiebing-fadongguo") == 0) --
    end,
    -- card_filter = function(self, player, to_select, selected)
    --   return #selected == 0 and not player:prohibitDiscard(to_select)
    -- end,
    target_filter = function(self, player, to_select, selected)
      return #selected == 0 and not to_select:isKongcheng() and to_select ~= player
    end,
    on_use = function(self, room, effect)
      local player = effect.from
      -- if(player:getMark("@md__jiebing-inhand-round") < 2) then
      --   room:addPlayerMark(player, "@md__jiebing-inhand-round", 1)
      -- end
      -- room:addPlayerMark(player, "md__jiebing-fadongguo", 1)
      local target = effect.tos[1]
    --   player:broadcastSkillInvoke(md__jiebing.name, 1)
      room:notifySkillInvoked(player, md__jiebing.name, "control")
      room:addTableMarkIfNeed(player, "md__jiebing-phase", target.id)
    --   room:throwCard(effect.cards, md__jiebing.name, player, player)
      room:damage{
        to = player,
        damage = 1,
        skillName = md__jiebing.name,
      }
      if player.dead then return end
    --   player:turnOver()
      if player.dead or target.dead or target:isKongcheng() then return end
    --   room:moveCardTo(target:getCardIds("h"), Card.PlayerHand, player, fk.ReasonPrey, md__jiebing.name, nil, false, player)
      local card1 = room:askToChooseCards(player, {
        min = 3,
        max = 3,
        target = target,
        flag = "h",
        skill_name = md__jiebing.name,
      })
      room:obtainCard(player, card1, false, fk.ReasonPrey)
      for _, cardId in ipairs(card1) do
        local card = Fk:getCardById(cardId)  -- 获取牌对象
        room:setCardMark(card, "@@md__jiebing-inhand-round", 1)
      end
    --   room:setCardMark(Fk:getCardById(card1[1]), "@@md__jiebing-inhand-round", 1)
    end,
  })
  
  -- md__jiebing:addEffect(fk.EventPhaseEnd, {
  --   mute = true,
  --   can_trigger = function(self, event, target, player, data)
  --     return target == player and player:hasSkill(md__jiebing.name) and player.phase == Player.Discard and player:getMark("md__jiebing-fadongguo") == 0
  --     and player:getMark("@md__jiebing-inhand-round") > 0
  --   end,
  --   on_use = function(self, event, target, player, data)
  --     local room = player.room
  --     -- player:removeMark("@md__jiebing-inhand-round", 1)
  --   end,
  -- })

  -- md__jiebing:addEffect(fk.EventPhaseStart, {
  --   mute = true,
  --   can_trigger = function(self, event, target, player, data)
  --     return target == player and player:hasSkill(md__jiebing.name) and player.phase == Player.Finish and player:getMark("md__jiebing-fadongguo") ~= 0
  --   end,
  --   on_use = function(self, event, target, player, data)
  --     local room = player.room
  --     room:setPlayerMark(player, "md__jiebing-fadongguo", 0)
  --   end,
  -- })

  md__jiebing:addEffect(fk.EventPhaseEnd, {
    mute = true,
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
      return target == player and player.phase == Player.Play and player:getMark("md__jiebing-phase") ~= 0
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
    --   player:broadcastSkillInvoke(md__jiebing.name, 2)
      room:notifySkillInvoked(player, md__jiebing.name, "control")
      local card2 = table.filter(player:getCardIds("h"), function (id)
        return Fk:getCardById(id):getMark("@@md__jiebing-inhand-round") > 0
      end)
      if #card2 == 0 then return end

      local targets = table.map(player:getMark("md__jiebing-phase"), Util.Id2PlayerMapper)
      -- player:removeMark("md__jiebing-phase", 1)
      room:sortByAction(targets)
      for _, to in ipairs(targets) do
        if player.dead or player:isNude() then return end
        if not to.dead then
          for _, id in ipairs(card2) do
            room:setCardMark(Fk:getCardById(id), "@@md__jiebing-inhand-round", 0)
          end
          room:moveCardTo(card2, Card.PlayerHand, to, fk.ReasonGive, md__jiebing.name, nil, false, player)
        end
      end
    end,
  })
  
  

  return md__jiebing
  